package com.ftg.learn.controller;

import com.ftg.learn.comm.Kjx;
import com.ftg.learn.dto.TeacherSaveDto;
import com.ftg.learn.dto.TeacherUpdateDto;
import com.ftg.learn.entity.TeacherEntity;
import com.ftg.learn.service.TeacherService;
import com.ftg.learn.util.PageEx;
import com.ftg.learn.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author 布衣
 * @RestController
 * @Service
 * @Component
 */
@RestController
@RequestMapping("/teacher")
@Tag(name = "教师接口")
public class TeacherController {

    @Value("${spring.datasource.username}")
    String username;

    @Resource
    private TeacherService teacherService;

    @Resource
    Kjx kjx;

    @GetMapping("/list")
    @Operation(summary = "获取所有教师(带分页功能)")
    @Parameters({
            @Parameter(name = "pageNum", description = "当前页码", required = true),
            @Parameter(name = "pageSize", description = "每页数量", required = true)
    })
    public R<PageEx<TeacherEntity>> getAll(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize
    ) {
        System.out.println(username + "====>");
        System.out.println(kjx.getPageNum());
        System.out.println(kjx.getPageSize());
        return teacherService.getAll(pageNum, pageSize);
    }


    @PostMapping("/save")
    @Operation(summary = "保存教师")
    public R<Boolean> saveTeacher(
           @RequestBody TeacherSaveDto teacherEntity
    ){
        return teacherService.saveTeacher(teacherEntity);
    }

    @PutMapping("/modify")
    @Operation(summary = "修改教师")
    public R<Boolean> modifyTeacher(
            @RequestBody TeacherUpdateDto teacherEntity
    ){
        return teacherService.modifyTeacher(teacherEntity);
    }


    @DeleteMapping("/deleteById/{id}")
    @Operation(summary = "删除老师")
    public R<Boolean> deleteTeacher(
            @PathVariable("id") Integer id
    ){
        return teacherService.deleteTeacher(id);
    }

}
